# -*- coding: utf-8 -*-  
#!/usr/bin/python2.7
"""各类过滤器。"""

__authors__ = [
  '"BigYuki" <sheyuqi@gmail.com>',
]

from datetime import tzinfo, timedelta

class TimeFilter:
    """处理时间的过滤器 。"""
    @staticmethod
    def ToLocalTime(naiveDateTime):
        return naiveDateTime.replace(tzinfo = UTC()).astimezone(UTC_8())
    @staticmethod
    def ToLocalTimeStr(naiveDateTime):
        """获取当地区时的时间字符串 。
        
        Args:
                naiveDateTime: datetime类型，0时区
        Returns:
            一个字符串，把对应0时区的时间转换为+8区的时间：
                2012-12-20 14:28。
        """
        return TimeFilter.ToLocalTime(naiveDateTime).strftime("%Y-%m-%d %H:%M")

class UTC(tzinfo):
    """UTC"""
    HOUR = timedelta(hours=0)
    def utcoffset(self, dt):
        return self.HOUR
    def tzname(self, dt):
        return "UTC"
    def dst(self, dt):
        return self.HOUR
    
class UTC_8(tzinfo):
    """UTC+8"""
    HOUR = timedelta(hours=8)
    def utcoffset(self, dt):
        return self.HOUR
    def tzname(self, dt):
        return "UTC+8"
    def dst(self, dt):
        return self.HOUR